<template>
  <div v-show="isShowGoods">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getGoodsDataList(activityId)">
      <!-- <el-form-item>
        <el-input v-model="dataForm.goodsName" placeholder="商品名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getGoodsDataList(activityId)">查询</el-button>
        <el-button @click="dataForm.goodsName=''
         getGoodsDataList(activityId)" type="info" plain >重置</el-button>
        <el-button v-if="isAuth('spike:goods:add')" type="primary" @click="addOrUpdateHandle()">添加商品</el-button>
        <el-button v-if="isAuth('spike:goods:remove')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
      </el-form-item> -->
    </el-form>
    <el-table
        :data="dataList"
        border
        v-loading="dataListLoading"
        @selection-change="selectionChangeHandle"
        style="width: 100%;">
        <!-- <el-table-column
          type="selection"
          header-align="center"
          align="center"
          width="50">
        </el-table-column> -->
        <el-table-column
          prop="id"
          header-align="center"
          align="center"
          label="活动整点ID">
        </el-table-column>
        <el-table-column
          prop="activiteTime"
          header-align="center"
          align="center"
          label="活动时间">
        </el-table-column>
        <el-table-column
          prop="beginTime"
          header-align="center"
          align="center"
          label="活动每日开始时间">
        </el-table-column>
        <el-table-column
          prop="endTime"
          header-align="center"
          align="center"
          label="活动每日结束时间">
        </el-table-column>
        <el-table-column
          prop="goodsCount"
          header-align="center"
          align="center"
          label="活动商品数量">
        </el-table-column>
        <el-table-column
          fixed="right"
          header-align="center"
          align="center"
          width="150"
          label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="forward1(scope.row.id,scope.row.state)">设置商品</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
      <!-- <div v-show="!isShow3" >
        <goods ref="Goods"></goods>
        <el-button @click="isShowTime3()" type="primary" round icon="el-icon-arrow-left">返回整点</el-button>
      </div> -->
    <!-- 弹窗, 新增 / 修改 -->
    <goods v-if="addOrUpdateVisible" ref="goods" @refreshDataList="getGoodsDataList"></goods>
    <!-- <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getGoodsDataList"></add-or-update>
    <specs-add-or-update v-if="dialogVisible" ref="specsAddOrUpdate" @refreshDataList="getGoodsDataList"></specs-add-or-update> -->


    <!-- <el-dialog title="修改" :visible.sync="sequenceVisible" width="20%">
      <el-form ref="form" :model="updateForm" label-width="70px">
        <el-form-item label="排序">
          <el-input v-model="updateForm.updateSequence" property="排序"></el-input>
        </el-form-item>
        <el-form-item label="销量">
          <el-input v-model="updateForm.updateSaleNum" property="销量"></el-input>
        </el-form-item>
      </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="sequenceVisible = false">取 消</el-button>
          <el-button type="primary" @click="sequenceUpdate()">确 定</el-button>
        </span>
    </el-dialog> -->
  </div>
</template>

<script>
  import Goods from './goods1'
//   import SpecsAddOrUpdate from './specs-add-or-update'
  export default {
    data () {
      return {
        dialogVisible: false,
        isShow3: true,
        isShowGoods: true,
        dataForm: {
          goodsName: '',
          activityId: 0
        },
        goodsSkuList: '[]',
        spikeActivityId: null,
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false,
        sequenceVisible: false,
        updateForm: {
          updateId: 0,
          updateSequence: '',
          updateSaleNum: ''
        }
      }
    },
    components: {
      Goods
    },
    // activated () {
    // },
    methods: {
      // 获取数据列表
      getGoodsDataLists (id) {
        if (id != null) {
          this.dataForm.activityId = id
        }
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/activity/spike/getWholePointActivitiesTime'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'keywords': this.dataForm.activityId
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.data.list
            this.totalPage = data.data.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      isShowTime3 () {
        // this.isShow3 = true
        this.isShow2 = true
        this.isShowGoods = false
      },
    //   sequenceUpdate () {
    //     this.$http({
    //       url: this.$http.adornUrl('/activity/spikeGoods/modify'),
    //       method: 'post',
    //       data: this.$http.adornData({
    //         'id': this.updateForm.updateId,
    //         'goodsSequence': this.updateForm.updateSequence,
    //         'goodsSaleNum': this.updateForm.updateSaleNum
    //       })
    //     }).then(({data}) => {
    //       if (data && data.code === 0) {
    //         this.$message({
    //           message: '操作成功',
    //           type: 'success',
    //           duration: 1500,
    //           onClose: () => {
    //             this.getGoodsDataList(this.activityId)
    //           }
    //         })
    //       } else {
    //         this.$message.error(data.msg)
    //       }
    //       this.sequenceVisible = false
    //     })
    //   },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getGoodsDataLists(this.activityId)
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getGoodsDataLists(this.activityId)
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 修改排序
    //   updateHandle (id, val, val1) {
    //     this.sequenceVisible = true
    //     this.updateForm.updateId = id
    //     this.updateForm.updateSequence = val
    //     this.updateForm.updateSaleNum = val1
    //   },
      // 删除
    //   deleteHandle (id) {
    //     var ids = id ? [id] : this.dataListSelections.map(item => {
    //       return item.id
    //     })
    //     this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
    //       confirmButtonText: '确定',
    //       cancelButtonText: '取消',
    //       type: 'warning'
    //     }).then(() => {
    //       this.$http({
    //         url: this.$http.adornUrl('/activity/spikeGoods/remove'),
    //         method: 'post',
    //         data: this.$http.adornData(ids, false)
    //       }).then(({data}) => {
    //         if (data && data.code === 0) {
    //           this.$message({
    //             message: '操作成功',
    //             type: 'success',
    //             duration: 1500,
    //             onClose: () => {
    //               this.getGoodsDataList(this.activityId)
    //             }
    //           })
    //         } else {
    //           this.$message.error(data.msg)
    //         }
    //       })
    //     })
    //   },
    //   specsHandle (id, val, goodsType) {
    //     this.dialogVisible = true
    //     this.$nextTick(() => {
    //       this.$refs.specsAddOrUpdate.init(id, JSON.parse(val), true, goodsType)
    //     })
    //   },
      forward1 (id, state) {
        debugger
        // localStorage.setItem('spikeActivityId', id)
        // localStorage.setItem('activityState', state)
        // this.isShow3 = false
        this.addOrUpdateVisible = true
        // this.isShowGoods = false
        this.$nextTick(() => {
          this.$refs.goods.init(id)
        })
      }
    }
  }
</script>
<style>
  .characters{
    width:300px;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
  }
</style>
